// login module

import { makeAutoObservable } from 'mobx'
import { http, setToken, getToken, removeToken } from '@/utils'

export default class LoginStore {
  token = getToken || ''
  constructor() {
    makeAutoObservable(this)
  }

  /* setToken = (token) => {
    this.token = token
  } */

  login = async ({ mobile, code }) => {
    const res = await http.post('/authorizations', {
      mobile,
      code,
    })
    // this.setToken(res.token)
    this.token = res.token
    setToken(this.token)
  }

  logout = () => {
    this.token = ''
    removeToken()
  }
}
